# Maintainer: Torsten Keßler <tpkessler at archlinux dot org>
# Contributor: Ranieri Althoff <ranisalt+aur at gmail dot com>

pkgname=rocm-device-libs
pkgver=5.7.1
pkgrel=1
pkgdesc='ROCm Device Libraries'
arch=('loong64' 'x86_64')
url='https://github.com/RadeonOpenCompute/ROCm-Device-Libs'
license=('custom:NCSAOSL')
makedepends=('rocm-cmake' 'rocm-llvm')
source=("${pkgname}-${pkgver}.tar.gz::$url/archive/rocm-$pkgver.tar.gz"
        "${pkgname}-rm-gfx700.patch")
sha256sums=('703de8403c0bd0d80f37c970a698f10f148daf144d34f982e4484d04f7c7bbef'
            '0b38ab6d8b1a52bac198007af098d6ec5008a7359a4ee174283e6c69c8b1a868')
_dirname="$(basename "$url")-$(basename "${source[0]}" .tar.gz)"

prepare() {
    cd "$_dirname"
    patch -Np1 -i "$srcdir/$pkgname-rm-gfx700.patch"
}

build() {
    cmake \
        -Wno-dev \
        -S "$_dirname" \
        -B build \
        -DCMAKE_C_COMPILER=/opt/rocm/llvm/bin/clang \
        -DCMAKE_BUILD_TYPE=None \
        -DCMAKE_INSTALL_PREFIX=/opt/rocm \
        -DLLVM_DIR=/opt/rocm/llvm/lib/cmake/llvm
    cmake --build build
}

check() {
    cmake --build build --target test
}

package() {
    DESTDIR="$pkgdir" cmake --install build
    install -Dm644 "$_dirname/LICENSE.TXT" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
